package com.dykj.fireFighting.web.controller;

import java.util.*;

import com.alibaba.nacos.api.annotation.NacosProperties;
import com.dykj.fireFighting.api.base.system.entity.SysDirectory;
import com.dykj.fireFighting.api.base.system.entity.SysDirectoryType;
import com.dykj.fireFighting.api.base.system.service.ISysDirectoryService;
import com.dykj.fireFighting.api.monitoringCenter.entity.PgRegion;
import com.dykj.fireFighting.api.monitoringCenter.service.IPgRegionService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.dto.CommonDto;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;



/**
 * 接口
 *
 * @Author JacksonTu
 * @Date  2022-02-10 13:36:22
 */
@Slf4j
@Api(value = "接口", tags = {"接口"})
@RestController
@RequestMapping("pgRegion")
public class PgRegionController {

    @DubboReference
    private IPgRegionService pgRegionService;
    @DubboReference
    private ISysDirectoryService directoryService;


    /**
     * 列表
     *
     * @return
     */
    @AutoLog(value = "-分页列表查询")
    @ApiOperation(value = "分页列表", notes = "分页列表")
    @GetMapping("/list")
    //@RequiresPermissions("pgRegion/list")
    public CommonResult<PageVo<PgRegion>> treeGrid(CommonDto commonDto) {
        PageVo<PgRegion> page = pgRegionService.pageList(commonDto);
        return CommonResult.success(page);
    }

    @AutoLog(value = "-列表查询")
    @ApiOperation(value = "列表", notes = "列表")
    @GetMapping("/listAll")
    //@RequiresPermissions("pgRegion/list")
    public CommonResult<List<PgRegion>> getList(CommonDto commonDto) {
        List<PgRegion> page = pgRegionService.list();
        return CommonResult.success(page);
    }
    /**
     * 列表
     *
     * @return
     */
    @AutoLog(value = "-字典表查询")
    @ApiOperation(value = "字典表查询", notes = "字典表查询")
    @GetMapping("/getDic")
    public CommonResult<Map<String,Object>> getDic() {
        Map<String,Object> map=new HashMap<>();
        List<SysDirectory> list=directoryService.queryDataByType("siteType");
        List<SysDirectory> list1 = directoryService.getByParentCode("130200000000");
        SysDirectory sysDirectory=directoryService.queryByCode("130200000000");
        list1.add(sysDirectory);
        map.put("region",list);
        map.put("siteType",list1);
        return CommonResult.success(map);
    }

    /**
     * 获取信息
     */
    @AutoLog(value = "-获取信息")
    @ApiOperation(value = "获取信息", notes = "获取信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", dataType = "String", required = true)
    @GetMapping("/info/{id}")
    //@RequiresPermissions("pgRegion/info")
    public CommonResult<PgRegion> info(@PathVariable("id") String id){
        PgRegion pgRegion = pgRegionService.getById(id);
        return CommonResult.success(pgRegion);
    }

    /**
     * 保存信息
     */
    @AutoLog(value = "-保存信息")
    @ApiOperation(value = "保存信息", notes = "保存信息")
    @PostMapping("/save")
    //@RequiresPermissions("pgRegion/save")
    public CommonResult save(@Valid @RequestBody PgRegion pgRegion) {
        try {
            pgRegion.setCreateBy(ShiroUtil.getUser().getId().toString());
            pgRegion.setCreateTime(new Date());
            pgRegion.setCenterId(ShiroUtil.getUser().getEnterpriseId().toString());
            pgRegionService.save(pgRegion);
            return CommonResult.success("添加成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 修改信息
     */
    @AutoLog(value = "-修改信息")
    @ApiOperation(value = "修改信息", notes = "修改信息")
    @PostMapping("/update")
    //@RequiresPermissions("pgRegion/update")
    public CommonResult update(@Valid @RequestBody PgRegion pgRegion) {
        try {
                pgRegionService.updateById(pgRegion);
            return CommonResult.success("修改成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 删除信息
     */
    @AutoLog(value = "-删除信息")
    @ApiOperation(value = "删除信息", notes = "删除信息")
    @ApiImplicitParam(paramType = "query", name = "ids", value = "ID数组", dataType = "String", required = true, allowMultiple = true)
    @PostMapping("/delete")
    //@RequiresPermissions("pgRegion/delete")
    public CommonResult delete(@RequestBody String[]ids) {
        try {
                pgRegionService.removeByIds(Arrays.asList(ids));
            return CommonResult.success("删除成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }
}
